/*
 * @Author: 0x9DEFA478
 * @Date: 2021-08-27 13:39:06
 * @LastEditTime: 2021-09-17 01:04:59
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "GUI_User_Page.h"
#include "Peripheral.h"



static int IsSave;


// static void BackCallback(void* page){
//   H_UI_Page* Page;
//   Page=page;
//   if(Page->UserInstence!=NULL){
//     H_StringItem_EventBack(Page->UserInstence);
//   }else{
//     H_UI_ExitSelect(Page->Parent);
//   }
// }

// static void EnterCallback(void* page){
//   H_UI_Page* Page;
//   Page=page;
//   if(Page->UserInstence!=NULL){
//     H_StringItem_EventEnter(Page->UserInstence);
//   }
// }

static void AddCallback(void* page){
  H_UI_Page* Page;
  Page=page;
  
  I_NVM_Save();
  IsSave=-1;
}

static void SubCallback(void* page){
  H_UI_Page* Page;
  Page=page;
  
  Peripherals_DeInit();
  H_TS_SchedulerSuspend();
  Bootloader_JumpDFU();

}

static void EnterPageCallback(void* page){
  IsSave=0;
}

// static void ExitPageCallback(void* page){
// }

static void DisplayPageCallback(void* page){
  H_UI_Page* Page;

  unsigned char strBuffer[32];
  char* str;
  int strWidth;
  int strHeight;

  Page=page;

  GUI_User_ClearBitmap(GUI_User_GetDrawStringBitmap());

  str="保存页面";
  H_Font_GetStringSize(Font_LLib_Song,str,&strWidth,&strHeight);
  GUI_User_DrawString(str,Font_LLib_Song,0,(128-strWidth)/2,0,127,63);

  if(((H_UI*)Page->Parent)->IsSelect==0){
    //无选中

    str="请选中以保存";
    H_Font_GetStringSize(Font_LLib_Song,str,&strWidth,&strHeight);
    GUI_User_DrawString(str,Font_LLib_Song,0,(128-strWidth)/2,32,127,63);
  }else{
    //选中

    if(IsSave==0){
      str="ADD:保存";
      H_Font_GetStringSize(Font_LLib_Song,str,&strWidth,&strHeight);
      GUI_User_DrawString(str,Font_LLib_Song,0,(128-strWidth)/2,32,127,63);

      str="SUB:进入DFU";
      H_Font_GetStringSize(Font_LLib_Song,str,&strWidth,&strHeight);
      GUI_User_DrawString(str,Font_LLib_Song,0,(128-strWidth)/2,48,127,63);
    }else{
      str="保存完成";
      H_Font_GetStringSize(Font_LLib_Song,str,&strWidth,&strHeight);
      GUI_User_DrawString(str,Font_LLib_Song,0,(128-strWidth)/2,32,127,63);
    }

  }
}

H_StringItem* GUI_User_Page_Save_Init(H_UI* h_ui,H_UI_Callbacks* Callbacks){

  GUI_User_Page_GetDefaultCallbacks(Callbacks);
  Callbacks->DisplayPageCallback=DisplayPageCallback;
  Callbacks->AddCallback=AddCallback;
  Callbacks->SubCallback=SubCallback;
  Callbacks->EnterPageCallback=EnterPageCallback;

  return NULL;
}

void GUI_User_Page_Save_DeInit(H_StringItem* stringitem){
}
